import Login from "../page/Login";
import Layout from "@/page/Layout";
import { lazy } from 'react'

import { createBrowserRouter } from 'react-router-dom'
import NotFound from "../page/404";

import { AuthRoute } from "@/components/AuthRoute";
import { Suspense } from "react";

/**
 * lazy函数对组件进行导入
 */
const Home = lazy(() => import('@/page/Home'));
const Article = lazy(() => import('@/page/Article'));
const Publish = lazy(() => import('@/page/Publish'));

const router = createBrowserRouter([
    {
        path: "/",
        element: 
        <AuthRoute>
            <Layout />
        </AuthRoute>,
        children: [
            {
                index: true,
                element: <Suspense fallback="加载中"><Home /></Suspense>
            },
            {
                path: "article",
                element: <Suspense fallback="加载中"><Article /></Suspense>
            },
            {
                path: "publish",
                element: <Suspense fallback="加载中"><Publish /></Suspense>
            }
        ]
    },
    {
        path: "/login",
        element: <Login />
    },
    {
        path: "/article/:id",
        element: <Article />
    },
    {
        path: "*",
        element: <NotFound />
    }
]);

export default router